const express = require('express');
const router = express.Router();

// router.use((req, res, next) => {
//   res.header("Access-Control-Allow-Origin", "*");
//   res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
//   res.header("Access-Control-Allow-Headers", "X-Requested-With");
//   res.header("Access-Control-Allow-Headers", "Content-Type");
//   next();
// });


const summarizeModel = require('../model/summarize');
/* GET home page. */
router.get('/', function (req, res, next) {
  summarizeModel.insertMany({
    id: 1,
    name: 23,
    success: '菜鸟教程',
    experience: 'http://www.runoob.com',
    harvest: "['mongodb', 'database', 'NoSQL']"
  }, (err, docs) => {
    if(err) console.log(err);
    console.log(docs);
  })
  // console.log(summarizeModel.save({}));
  summarizeModel.find({}, function (err, docs) {
    if (err) {
      res.json({
        success: 'fail',
        data: null
      })
    } else {
      res.json({
        success: 'true',
        data: docs
      })
    }
  })
});

module.exports = router;